package com.boot.security.server.service.impl.mffl.Mfflbankcard;

import com.boot.security.server.dao.mffl.MfflBankcardDao;
import com.boot.security.server.model.SysUser;
import com.boot.security.server.model.mffl.MfflBankcard;
import com.boot.security.server.utils.UserUtil;
import com.boot.security.server.utils.mffl.ReturnBean;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

/**
 * 银行卡业务
 */
@Service
public class BankCardService {

    //银行卡
    @Autowired
    private MfflBankcardDao mfflBankcardDao;


    //获取银行卡信息
    public ReturnBean<MfflBankcard> showBankCard(){
        //获取当前用户
        ReturnBean returnBean = new ReturnBean();
        SysUser sysUser = UserUtil.getLoginUser();
        MfflBankcard UserIdBankcard = mfflBankcardDao.getByUserId(sysUser.getId().intValue());
        if(UserIdBankcard == null){
            returnBean.setReturnBean("134");
            return returnBean;
        }
        returnBean.setDatas(UserIdBankcard);
        return returnBean;
    }


    //设置银行卡信息
    public ReturnBean SetupBankCard(String bankcardnumber,String bank,String realname){
        ReturnBean returnBean = new ReturnBean();
        //获取当前用户
        SysUser sysUser = UserUtil.getLoginUser();
        MfflBankcard UserIdBankcard = mfflBankcardDao.getByUserId(sysUser.getId().intValue());

        if (UserIdBankcard == null){
            //新增
            MfflBankcard mbc = new MfflBankcard();
            mbc.setBank(bank);
            mbc.setBankcardnumber(bankcardnumber);
            mbc.setUserid(sysUser.getId().intValue());
            Date date = new Date();
            mbc.setCreateTime(date);
            mbc.setUpdateTime(date);
            mbc.setDeletestate(1);
            mbc.setDeleteTime(date);
            mbc.setRealname(realname);
            mfflBankcardDao.save(mbc);
        }else{
            //修改
            MfflBankcard mbc = new MfflBankcard();
            mbc.setId(UserIdBankcard.getId());
            mbc.setBank(bank);
            mbc.setBankcardnumber(bankcardnumber);
            mbc.setRealname(realname);
            mbc.setUpdateTime(new Date());
            mfflBankcardDao.update(mbc);
        }
        return returnBean;
    }
}
